# !/usr/bin/env python
# -*-coding:utf-8 -*-
"""
# File       : MakeDataMain.py
# Time       ：2023-08-11 14:39
# Author     ：张铨
# version    ：
# Description：
"""
import sys

from PyQt5.QtCore import pyqtSlot, Qt
from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox, QComboBox, QWidget

from MakeData import Ui_MainWindow
from about import Ui_Dialog

from utils.MyThread import BackThread
from utils.idaddress import ID_address


class MainWindow(QMainWindow, Ui_MainWindow):
    # 线程参数列表，依次为类型，个数，指定条件
    paramList = []
    # 指定条件列表
    paramSureList = []

    def __init__(self):
        super(MainWindow, self).__init__()
        self.setFixedSize(424, 418)
        self.setupUi(self)
        self.mythread = BackThread()
        self.mythread.finished.connect(self.threadmsg)
        self.mythread.dataSingnal.connect(self.datamsg)
        self.mythread.dataListSingal.connect(self.datalistmsg)
        self.comBoxInit()
        # self.Province_comboBox.setSizeAdjustPolicy(QComboBox.AdjustToContents)
        self.ProvinceNext_comboBox.setSizeAdjustPolicy(QComboBox.AdjustToContents)

    @pyqtSlot()
    def threadmsg(self):
        print("线程完成")

    # 获取信号，对编辑框进行填充
    @pyqtSlot(str)
    def datamsg(self, nameStr):
        print(nameStr)
        self.textEdit.setText(nameStr)

    # 获取信号中列表信息，对编辑框进行填充
    @pyqtSlot(list)
    def datalistmsg(self, msglist):
        self.textEdit.clear()
        print(msglist)
        textStr = ''
        for data in msglist:
            self.textEdit.append(data)

    def On_Init2ComBox(self):

        comboxProviceStr = self.Province_comboBox.currentText()
        self.nextComboxlist = []

        for key, value in ID_address.items():
            if comboxProviceStr in value:
                self.nextComboxlist.append(value)
        self.ProvinceNext_comboBox.clear()
        print(self.nextComboxlist)
        showListStr = self.nextComboxlist[1:]
        self.ProvinceNext_comboBox.addItems(showListStr)

        # combx1text = self.Province_comboBox.currentText()
        # # print(combx1text)
        # self.province_list_next = []
        # for key, value in ID_address.items():
        #
        #     if combx1text in value:
        #         # print(value)
        #         # print(key)
        #         self.province_list_next.append(value)
        #     # print(self.province_list_next)
        #
        # #更新combox2 的内容
        # self.comboBox_province_next.clear()
        #
        # self.ProvinceNext_comboBox.addItems(self.province_list_next)
        print("初始化2")

    def comBoxInit(self):
        ##初始化第一个下拉列表
        province_list = ['北京市', '天津市', '河北省', '山西省', '内蒙古自治区', '辽宁省', '吉林省', '黑龙江省', '上海市', '江苏省', '浙江省', '安徽省', '福建省',
                         '江西省', '山东省', '河南省', '湖北省', '湖南省', '广东省', '广西壮族自治区', '海南省', '重庆市', '四川省', '贵州省', '云南省',
                         '西藏自治区', '陕西省', '甘肃省', '青海省', '宁夏回族自治区', '新疆维吾尔自治区']

        self.Province_comboBox.addItems(province_list)

    def On_MyOpenFile(self):
        QMessageBox.about(self, '说明', '后续根据需要保留的窗口')


    def On_MyAbout(self):
        QMessageBox.about(self, '说明', 'python练习\n联系qq:1473658931')

    # 获取生成参数对text编辑框进行操作
    def commonOperation(self, flag=""):
        # 清空参数列表
        self.paramList.clear()
        self.paramSureList.clear()
        # 重新获取参数
        typeparam = self.InfoType_comboBox.currentText()
        CNum = self.NumLineEdit.text()
        # 指定身份证信息获取四个参数
        if flag == "1":
            # 获取指定参数信息
            provinceParam = self.Province_comboBox.currentText()
            prvinceNextParam = self.ProvinceNext_comboBox.currentText()
            dateParam = self.dateEdit.text()
            sexParm = self.Sex_comboBox.currentText()
            self.paramSureList.append(provinceParam)
            self.paramSureList.append(prvinceNextParam)
            self.paramSureList.append(dateParam)
            self.paramSureList.append(sexParm)
        # 指定社会统一代码，获取两个信息
        elif flag == "2":
            # 获取指定参数信息
            provinceParam = self.Province_comboBox.currentText()
            prvinceNextParam = self.ProvinceNext_comboBox.currentText()
            dateParam = self.dateEdit.text()
            sexParm = self.Sex_comboBox.currentText()
            self.paramSureList.append(provinceParam)
            self.paramSureList.append(prvinceNextParam)

        if CNum == '':
            print("未输入个数")
            # 未输入个数默认为1个。
            CNum = '1'
        else:
            CNum = self.NumLineEdit.text()
        self.paramList.append(typeparam)
        self.paramList.append(CNum)
        self.paramList.append(self.paramSureList)
        # 传递参数
        self.mythread.getparam(self.paramList)
        self.mythread.start()

    def On_MyGenerater(self):
        # 根据需要生成的类型进行传递参数。
        try:
            if self.InfoType_comboBox.currentText() == "姓名":
                '''
                功能完成
                '''
                self.commonOperation()
                self.NumLineEdit.clear()
                # #点击姓名生成时候，对其他不必要控件进行置灰#TODO 针对下拉进行判断后续进行
                # self.Province_comboBox.setEnabled(False)
                # self.ProvinceNext_comboBox.setEnabled(False)
                # self.dateEdit.setEnabled(False)
                # self.Sex_comboBox.setEnabled(False)
            elif self.InfoType_comboBox.currentText() == "身份证（指定）":
                self.commonOperation("1")
            elif self.InfoType_comboBox.currentText() == "身份证（随机）":
                '''
                功能完成
                '''
                self.commonOperation()
            elif self.InfoType_comboBox.currentText() == "统一社会信用代码（指定）":
                self.commonOperation("2")
            elif self.InfoType_comboBox.currentText() == "统一社会信用代码（随机）":
                self.commonOperation()
            elif self.InfoType_comboBox.currentText() == "组织信用代码":
                self.commonOperation()
            elif self.InfoType_comboBox.currentText() == "公司名称":
                self.commonOperation()
            elif self.InfoType_comboBox.currentText() == "组合信息生成":
                self.commonOperation()
            elif self.InfoType_comboBox.currentText() == "测试汉字字数":
                self.commonOperation()
            elif self.InfoType_comboBox.currentText() == "测试英文字数":
                self.commonOperation()
            elif self.InfoType_comboBox.currentText() == "测试特殊字符":
                self.commonOperation()

        except Exception as e:
            print(e)


class aboutWindow( QWidget,Ui_Dialog):
    def __init__(self):
        super(aboutWindow, self).__init__()
        self.setupUi(self)




if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())
